package com.unionftech.content_login.api.mock

import com.unionftech.baselibrary.network.RetrofitClient

class MockServer {

    private lateinit var mockLoginApi: MockLoginApi
    private lateinit var mockRegisterApi: MockRegisterApi

    companion object {
        const val MOCK_EMAIL_ACCOUNT_LIST = "mock_email_account_list"
        const val MOCK_PHONE_ACCOUNT_LIST = "mock_phone_account_list"

        @Volatile
        private var instance: MockServer? = null

        @JvmStatic
        fun getInstance() = instance ?: synchronized(this) {
            instance ?: MockServer().also {
                instance = it
            }
        }
    }

    fun apiMockLogin(): MockLoginApi {
        if (!::mockLoginApi.isInitialized) {
            val delegate = RetrofitClient.getInstance().createMock(LoginMockApi::class.java)
            mockLoginApi = MockLoginApi(delegate)
        }
        return mockLoginApi
    }

    fun apiMockRegister(): MockRegisterApi {
        if (!::mockRegisterApi.isInitialized) {
            val delegate = RetrofitClient.getInstance().createMock(RegisterMockApi::class.java)
            mockRegisterApi = MockRegisterApi(delegate)
        }
        return mockRegisterApi
    }
}